package com.Threads;

import java.util.ArrayList;
import java.util.List;

/*
 * 3.	Avem o clasa care are o metoda ce adauga intr-o lista numerele de la 1 la 5. 
 * Creati clasele necesare astfel incat intotdeatuna numerele sa fie adaugate in ordinea 1,2,3,4,5
 * indiferent daca sunt mai multe threaduri care adauga numeral intr-o lista.
 */
public class Ex3 {

	public static void main(String[] args) {

		
		
		for (int i = 0; i < 50; i++) {
			new Thread(new Numbers()).start();
		}
	}
}

class Numbers implements Runnable {

	static List<Integer> number = new ArrayList<Integer>();

	
	public void addNumbers() {

		synchronized (number) {

			for (int i = 1; i <= 5; i++) {

				number.add(i);
			}
			printList();
		}
	}

	@Override
	public void run() {

		addNumbers();

	}

	public void printList() {
		System.out.println(number);
	}

}
